home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v8n04.arc / WAIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-31  |  2.5 KB  |  66 lines

  1.  (*****************    W A I T   *************************
  2.  * Delays NumberOfSecs seconds.  This is done by         *
  3.  * accessing the PC clock via function $2C of DOS int    *
  4.  * 21h.  Its accuracy is limited by the fact that the    *
  5.  * time is calculated from the ROM BIOS tick count,      *
  6.  * which is updated only about 18.2 times per second.    *
  7.  * This means that Wait will be accurate to about        *
  8.  * 1/18 second.                                          *
  9.  *                                                       *
  10.  * Requires "Uses DOS" if in TP4 or TP5                  *
  11.  ******************    W A I T   ************************)
  12.  
  13.   PROCEDURE Wait(NumberOfSecs : Real);
  14.   CONST
  15.     Secs_PER_DAY = 86400.0; {60 * 60 * 24}
  16.   VAR
  17.     TimeIsUp : Boolean;
  18.     StartingSecs,
  19.     Secs : Real;
  20.  
  21.     (******************   READ CLOCK  ************************
  22.     *                                                        *
  23.     *  Reads the PC clock, by using service $2C of int 21h.  *
  24.     *  This service returns information in the 8088          *
  25.     *  registers as follows:                                 *
  26.     *                                                        *
  27.     *    CH      Hour                  (0 through 23)        *
  28.     *    CL      Minute                (0 through 59)        *
  29.     *    DH      Seconds               (0 through 59)        *
  30.     *    DL      Hundredths of seconds (0 through 99)        *
  31.     *******************   READ CLOCK  ***********************)
  32.  
  33.     PROCEDURE ReadClock(VAR Secs : Real);
  34.  
  35.     CONST
  36.       Secs_PER_HOUR = 3600.0; {This must be a real constant!}
  37.       Secs_PER_MINUTE = 60.0;
  38.     TYPE {Delete this type for TP4 and TP5}
  39.       Registers = RECORD
  40.         CASE Boolean OF
  41.           True : (AL,AH,BL,BH,CL,CH,DL,DH:Byte);
  42.           False : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:Integer)
  43.         END;
  44.     VAR Register : Registers;
  45.     BEGIN
  46.       Register.AH := $2C;
  47.       msDos(Register);
  48.       Secs := Secs_PER_HOUR*(Register.CH)
  49.                 +Secs_PER_MINUTE*(Register.CL)
  50.                 +Register.DH
  51.                 +0.01*Register.DL;
  52.     END;
  53.  
  54. {********************** BODY OF WAIT ************************}
  55.  
  56.   BEGIN
  57.     ReadClock(StartingSecs);
  58.     REPEAT
  59.       ReadClock(Secs);
  60.       IF Secs-StartingSecs >= 0.0 THEN {Normal situation.}
  61.         TimeIsUp := Secs-StartingSecs >= NumberOfSecs
  62.       ELSE {During call, clock has ticked past midnight.}
  63.         TimeIsUp := Secs_PER_DAY-StartingSecs+Secs >= NumberOfSecs
  64.     UNTIL TimeIsUp
  65.   END;
  66.